// Obliczyc wspolczynniki rozwiniecia dwumianu Newtona (a+b)^n korzystajac z trojkata Pascala.

#include <QCoreApplication>
#include <QVector>
#include <QSemaphore>
#include <QString>
#include <iostream>

#include "pascaltriangle.h"
#include "computethread.h"
#include "sleepyhead.h"

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    int n = 17; //9
    int threadsNumber = 50;
    int sleep = 50;
    QVector<ComputeThread*> threads(threadsNumber);
    QSemaphore *semaphore = new QSemaphore(threadsNumber);
    PascalTriangle p(n);

    for(int i=0; i<threads.size(); i++) {
        QString number;
        number.setNum(i+1);
        number = "Watek " + number;

        threads[i] = new ComputeThread(number, p.getTriangle(), sleep, semaphore);
        threads[i]->start();
    }

    Sleepyhead::msleep(sleep);

    while (semaphore->available() != threadsNumber) {
    }

    p.print();

//    for (int i = 0; i < threads.size(); i++) {
//        delete threads[i];
//    }

    delete semaphore;

    return app.exec();
}
